import React, { useMemo, useContext,useEffect } from 'react'
import SearchForm from '../CommonSearch'
import { Select, Form } from 'antd'
import cx from '@/assets/cx.png'
import cz from '@/assets/cz.png'
const { Option } = Select
import { Search } from '../../App'

const SearchInfo = (props) => {
    const {onSubmit} = props
    const ctx = useContext(Search)
    useEffect(() => {
        form.setFieldsValue(ctx.initialValue)
    },[])
    const formList = useMemo(() => {

        return [
            {
                name: 'response',
                child: <Select style={{ width: 400, height: 32 }}
                // defaultValue={ctx.response}
                >

                    <Option value="USD">$</Option>
                    <Option value="CNY">¥</Option>
                </Select>,
                label: '责任单位',
            },
            {
                name: 'grid',
                child: <Select style={{ width: 400, height: 32 }}
                // defaultValue={ctx.grid}
                >
                    <Option value="dUSD">333</Option>
                    <Option value="cCNY">555</Option>
                </Select>,
                label: '网格位',
            },
        ]
    }, [])


    const submit = () => {
        onSubmit(form.getFieldsValue(true))
        return
    }

    const reset = () => {
        form.resetFields()
        onSubmit(form.getFieldsValue(true))
    }
    const [form] = Form.useForm();
    return (
        <div>
            <SearchForm formList={formList} form={form}>
                <div style={{ display: 'flex', width: 176, position: 'absolute', right: 30 }}>
                    <div onClick={() => submit()} style={{ cursor: 'pointer', marginRight: 16 }}><img src={cx} height={32} style={{ objectFit: 'cover' }}></img></div>
                    <div onClick={() => reset()} style={{ cursor: 'pointer' }}><img src={cz} style={{ objectFit: 'cover', }} height={32}></img></div>
                </div>
            </SearchForm>
        </div>
    )

}

export default React.memo(SearchInfo)